<?php
/**
 * @package SQL
 * @subpackage Query
 *
 */
class Lead_Sql_Query_Factory
{
	static private $_operators = array(
    	'=' => array('className' => 'Equals', 'isNegated' => false),
    	'>' => array('className' => 'GreaterThan', 'isNegated' => false),
    	'<' => array('className' => 'LesserThan', 'isNegated' => false),
    	'<=' => array('className' => 'LesserThanOrEquals', 'isNegated' => false),
    	'>=' => array('className' => 'GreaterThanOrEquals', 'isNegated' => false),
    	'!=' => array('className' => 'Equals', 'isNegated' => true),
    	'LIKE' => array('className' => 'Like', 'isNegated' => false),
    	'!LIKE' => array('className' => 'Like', 'isNegated' => true),
    	'ILIKE' => array('className' => 'ILike', 'isNegated' => false),
    	'!ILIKE' => array('className' => 'ILike', 'isNegated' => true),
    	'IN' => array('className' => 'In', 'isNegated' => false),
    	'!IN' => array('className' => 'In', 'isNegated' => true),
	);
	
	static private $_joins = array(
    	'inner' => 'Inner',
    	'left' => 'Left',
    	'right' => 'Right'	
	);
	
		
	static public function operator($operator)
	{
		$operator = strtoupper($operator);
	    Zend_Loader::loadClass('Lead_Sql_Query_Operator');
		
		if(!key_exists($operator, self::$_operators))
			throw new Exception("Unsupported operator '{$operator}'");
		
		$className = 'Lead_Sql_Query_Operator_' . self::$_operators[$operator]['className'];
			
	    Zend_Loader::loadClass($className);
			
		// require_once dirname(__FILE__) . "/class." . SQLFactory::$operatorTbl[$operator]['className'] . ".php";
			
		$operatorObj = new $className(self::$_operators[$operator]['isNegated']);
		return $operatorObj;
	}
	
	
	static public function join($table, $joinType, $joinClause, $alias)
	{
	    $joinType = strtolower($joinType);
	    Zend_Loader::loadClass('Lead_Sql_Query_Join');
	
		
		if(!key_exists($joinType, self::$_joins))
			throw new Exception("Unsupported join");

		$className = 'Lead_Sql_Query_Join_' . self::$_joins[$joinType];
	
	    Zend_Loader::loadClass($className);
		
		$joinObj = new $className($table, $joinClause, $alias);
		return $joinObj;

		
	}
	
	
}